package ifosup.matthias.url;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {

	public static void main(String[] args)
	{
		try {
			URL url = new URL("http://www.google.fr");
			try {
				URLConnection urlConnec = (HttpURLConnection) url.openConnection();
				for (String key : urlConnec.getHeaderFields().keySet())
				{
					System.out.println("key "+key+" "+urlConnec.getHeaderField(key));
				}
				InputStream in = urlConnec.getInputStream();
				int i =0;
				StringBuffer sb = new StringBuffer();
				while((i=in.read())>0)
				{
					sb.append((char)i);
				}
				System.out.println(sb);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
